-- CAN_USE_SPELL

-------------------------------
-- 能否使用卷轴
-- @param classId
return function(classId)
    -- 判断需求技能是否满足
    local forbiddenSkillId = SpellM.query(classId, "forbidden_skill_id");
    local skillId;
    local skills = ME.user:getAllSkills();
    if type(forbiddenSkillId) == "table" and #forbiddenSkillId > 0 then
        -- 禁用时需要加入灵魂链接冈布奥的技能
        local lictor = ME.user.dbase:query("lictor_pets");
        local pet;
        local id;
        if lictor ~= nil then
            for _, id in pairs(lictor) do
                pet =  PetM.getMyPet(id);
                if pet then
                    skills = table.append(skills, pet:getAllSkills());
                end
            end
        end

        for _, skillId in pairs(forbiddenSkillId) do
            repeat
                -- 拥有该技能则禁止使用
                if table.indexOf(skills, skillId) > 0 then
                    local name = SpellM.query(classId)["desc"];
                    return string.format(getLocStr("forbidden_use_spell"), name);
                end

                -- 取下一个等级技能
                skillId = SkillM.getRow(skillId).next;
                if type(skillId) ~= "number" then
                    break;
                end
            until not skillId or skillId <= 0;
        end
    end

    local requireSkillId = SpellM.query(classId, "require_skill_id");
    if type(requireSkillId) ~= "table" or #requireSkillId == 0 then
        -- 没有需求
        return true;
    end

    for _, skillId in pairs(requireSkillId) do
        repeat
            -- 拥有该技能
            if table.indexOf(ME.user:getAllSkills(), skillId) > 0 then
                return true;
            end

            -- 取下一个等级技能
            skillId = SkillM.getRow(skillId).next;
            if type(skillId) ~= "number" then
                break;
            end
        until not skillId or skillId <= 0;
    end

    -- 获取该卷轴施放的技能，是否有不受限制属性
    local skillId   = SpellM.query(classId, "cast_skill_id");
    local prop      = PropM.combine(ME.user, "magic_unlimited", SkillM.query(skillId, "style"));
    if tonumber(prop[3]) > 0 then
        return true;
    end

    return false;
end